//
//  HomeCollectionViewCell.m
//  Systetagram
//
//  Created by 欧杨 on 2021/1/4.
//

#import "HomeCollectionViewCell.h"
#import "ImageViewController.h"

@implementation HomeCollectionViewCell

- (void)layoutSubviews
{
    self.backgroundColor = UIColor.lightGrayColor;
    self.clipsToBounds = NO;
    self.layer.masksToBounds = NO;
    self.layer.cornerRadius = 2;
}

- (void)configureGesture
{
    UITapGestureRecognizer *singleGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleClicked)];
    singleGesture.numberOfTapsRequired = 1;
    
    UITapGestureRecognizer *doubleGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleClicked)];
    doubleGesture.numberOfTapsRequired = 2;
    
    [singleGesture requireGestureRecognizerToFail:doubleGesture];
    
    [self setGestureRecognizers:[NSArray arrayWithObjects:singleGesture, doubleGesture, nil]];
}

-(void)singleClicked
{
    NSLog(@"single tap");
    ImageViewController *VC = [[ImageViewController alloc] initWithBlogModel:self.model andImage:self.image];
    [[self viewController].navigationController pushViewController:VC animated:YES];
}

-(void)doubleClicked
{
    UIImageView *heart = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    heart.image = [[UIImage imageNamed:@"like"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    heart.tintColor = UIColor.redColor;
    heart.center = self.center;
    [self.contentView addSubview:heart];
    [UIView animateWithDuration:0.2 animations:^{
           
           // transform 使...变形
           // CGAffineTransformMakeScale(1.2, 1.2) 缩放的比例 缩放为原来的1.2倍
            heart.transform = CGAffineTransformMakeScale(1.5, 1.5);
        } completion:^(BOOL finished) {
            // 完成后要将视图还原
            // CGAffineTransformIdentity
            [UIView animateWithDuration:0.2 animations:^{
                heart.transform = CGAffineTransformIdentity;
                [heart removeFromSuperview];
            }];
        }];
}

#pragma mark 获得当前view的控制器
- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController
                                          class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

@end
